using DimensionsHelper.LanguageService.Symbols;
using DimensionsHelper.LanguageService.Syntax;

namespace DimensionsHelper.LanguageService;

public class AnalysisExpressionStatement : AnalysisStatement
{
    private readonly AnalysisExpression _expression;

    internal AnalysisExpressionStatement(ExpressionStatement syntaxNode, AnalysisExpression expression,
        AnalysisNode? parent)
        : base(AnalysisBoundKinds.ExpressionStatement, syntaxNode, parent)
    {
        Syntax = syntaxNode;
        _expression = expression;
        _expression.Parent = this;
    }

    public override int ChildrenCount => 1;

    public override ExpressionStatement Syntax { get; }

    public override IEnumerable<AnalysisNode> GetChildren()
    {
        return [_expression];
    }

    internal override void AddChild(AnalysisNode child)
    {
        throw new NotSupportedException("ExpressionStatement cannot have children.");
    }
}

public static partial class AnalysisNodeFactory
{
    /// <summary>
    /// 创建一个表达式语句
    /// </summary>
    /// <param name="syntaxNode">原始语法节点</param>
    /// <param name="expression">表达式</param>
    /// <param name="parent">父节点，可以忽略</param>
    /// <param name="withSymbol">语法节点所在的With语句上下文类型符号</param>
    public static AnalysisExpressionStatement ExpressionStatement(ExpressionStatement syntaxNode,
        AnalysisExpression expression, AnalysisNode? parent, ITypeSymbol? withSymbol)
    {
        return new AnalysisExpressionStatement(syntaxNode, expression, parent).WithContainingWithSymbol(withSymbol);
    }
}